package com.ruge.user.controller;

import com.ruge.core.response.Response;
import com.ruge.user.service.UserLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author ruge.wu
 * @since 2022/2/11 16:02
 */

@Slf4j
@Validated
@RestController
@RequestMapping("user/location")
@Api(tags = "【用户 位置坐标 接口】", value = "【用户 位置坐标 接口】")
public class UserLocationController {

    @Resource
    private UserLocationService userLocationService;

    @PostMapping("updateLocationByAid")
    @ApiOperation(value = "【位置坐标】  更新用户的经纬度")
    Response updateLocationByAid(@Valid
                                 @ApiParam(value = "用户id") @RequestParam("aid") Long aid,
                                 @ApiParam(value = "用户的纬度") @RequestParam("lon") Float lon,
                                 @ApiParam(value = "用户的经度") @RequestParam("lat") Float lat) {
        return userLocationService.updateLocationByAid(aid, lon, lat);
    }

    @GetMapping("getNearMe")
    @ApiOperation(value = "【位置坐标】  获取附近的人")
    Response getNearMe(@Valid
                       @ApiParam(value = "用户id") @RequestParam("aid") Long aid,
                       @ApiParam(value = "用户id") @RequestParam("aid") Integer radius,
                       @ApiParam(value = "用户的纬度") @RequestParam("lon") Double lon,
                       @ApiParam(value = "用户的经度") @RequestParam("lat") Double lat) {
        return userLocationService.getNearMe(aid, radius, lon, lat);
    }
}
